home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABLinkedList.c
-
- NAME
- ABLinkedList.c, part of the ABox project source code,
- responsible for handling the AboutBox linked list class stuff.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 9 June 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
-
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABLinkedList.h"
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
- /*=============================== ABLink::ABLink ================================*/
-
- ABLink::ABLink(void)
- {
- mPreviousLink = NULL;
- mThisLink = this;
- mNextLink = NULL;
-
- } // end ABLink
-
-
- /*=============================== ABLink::~ABLink ================================*/
-
- ABLink::~ABLink(void)
- {
- this->Unlink();
- } // end ~ABLink
-
-
- /*=============================== ABLink::Data ================================*/
- void *ABLink::Data(void)
- {
- // this function should be overridden!!!
- return NULL;
- } // end Data
-
-
-
-
- /*=============================== ABLink::FindHead ================================*/
- ABLink *ABLink::FindHead(void)
- {
- ABLink *thing = this;
-
- while (thing->HasPreviousLink())
- {
- thing = thing->PreviousLink();
- } // end while block
-
- if (thing->DoesntHaveThisLink())
- // we've found the ABLinkedList "head" element,
- // so back off once and find the first element, if
- // one does indeed exist
- return thing->NextLink();
- else
- // nope, this must be a disembodied link item,
- // without the proper "head" or "tail" elements
- // present in an ABLinkedList
- return thing;
- } // end FindHead
-
-
-
-
- /*=============================== ABLink::FindTail ================================*/
- ABLink *ABLink::FindTail(void)
- {
- ABLink *thing = this;
-
- while (thing->HasNextLink())
- {
- thing = thing->NextLink();
- }
-
- if (thing->DoesntHaveThisLink())
- // we've found the ABLinkedList "tail" element,
- // so back off once and find the last element, if
- // one does indeed exist
- return thing->PreviousLink();
- else
- // nope, this must be a disembodied link item,
- // without the proper "head" or "tail" elements
- // present in an ABLinkedList
- return thing;
- } // end FindTail
-
-
-
- /*=============================== ABLink::Unlink ================================*/
- void ABLink::Unlink(void)
- {
- if (this->HasPreviousLink())
- this->PreviousLink()->NextLink() = this->NextLink();
-
- if (this->HasNextLink())
- this->NextLink()->PreviousLink() = this->PreviousLink();
-
- } // end Unlink
-
-
-
-
- /*=============================== ABLink::ExchangeWith ================================*/
- //
- // This method will return the _OLD_ link, the one that you are replacing.
- //
- ABLink *ABLink::ExchangeWith(ABLink *newGuy)
- {
- if (newGuy)
- {
- ABLink *link;
-
- // previousNode <---+ <----+
- // previous | |
- // next --+ | ---+ |
- // | | | |
- // this <-+ | <+ newGuy <--+ | <+
- // previous ----+ | previous -----+ |
- // next --+ | next ---+ |
- // | | | |
- // nextNode <-+ | <--+ |
- // previous --------+ --------+
- // next
- //
- if (this->HasPreviousLink())
- this->PreviousLink()->NextLink() = newGuy;
- link = this->PreviousLink();
- this->PreviousLink() = newGuy->PreviousLink();
- newGuy->PreviousLink() = link;
-
- if (this->HasNextLink())
- this->NextLink()->PreviousLink() = newGuy;
- link = this->NextLink();
- this->NextLink() = newGuy->NextLink();
- newGuy->NextLink() = link;
- } // end if block
-
- return this;
-
- } // end ExchangeWith
-
-
-
-
- /*=============================== ABLink::Ordinal ================================*/
- ABIndex ABLink::Ordinal(void)
- {
- ABLink *head;
- ABLink *tail;
- ABLink *t;
-
- ABIndex marker;
-
- // begin here...
-
- if (!(this->HasPreviousLink() && this->HasNextLink()))
- {
- return 1;
- } else {
- head = this->FindHead();
- tail = this->FindTail();
-
- marker = 1;
- t = head;
- while ((t != this) && (t != tail))
- {
- t = t->NextLink();
- ++marker;
- } // end while
-
-
- if (t == this)
- return marker;
- else
- return 0;
- } // end if else block
- } // end Ordinal
-
-
-
-
-
-
-
-
- /*=============================== ABLinkedList::ABLinkedList ================================*/
- ABLinkedList::ABLinkedList(void)
- {
- mListCount = 0;
- mHead.PreviousLink() = mHead.ThisLink() = NULL;
- mHead.NextLink() = NULL;
- mTail.PreviousLink() = NULL;
- mTail.NextLink() = mTail.ThisLink() = NULL;
- mCurrentLink = NULL;
- } // end ABLinkedList
-
-
- /*=============================== ABLinkedList::~ABLinkedList ================================*/
- ABLinkedList::~ABLinkedList(void)
- {
- ABLink *link = NULL;
-
- while (this->IsntEmpty())
- {
- link = this->NthLink(this->Count());
- if (link)
- link->Unlink();
- delete link;
- --(this->ListCount());
- } // end while
-
- } // end ~ABLinkedList
-
-
-
-
-
- /*=============================== ABLinkedList::Append ================================*/
- ABLinkedList *ABLinkedList::Append(ABLink *item)
- {
- if (this->Tail().HasPreviousLink())
- {
- // point the last item to this new item
- this->Tail().PreviousLink()->NextLink() = item;
- } // end if block
-
- // make the new item the last item
- item->NextLink() = &this->Tail();
- // point new item back to the former last item
- item->PreviousLink() = this->Tail().PreviousLink();
- this->Tail().PreviousLink() = item;
-
- if (this->Head().DoesntHaveNextLink())
- {
- // make the new item the first item
- this->Head().NextLink() = item;
- item->PreviousLink() = &this->Head();
- } // end if block
-
- ++(this->ListCount());
- this->CurrentLink() = item;
-
- return this;
- } // end Append
-
-
-
-
- /*=============================== ABLinkedList::Delete ================================*/
- ABLinkedList *ABLinkedList::Detach(ABLink *item)
- {
- if (item)
- {
- if (item == this->CurrentLink())
- this->CurrentLink() = item->PreviousLink();
- if (this->DoesntHaveCurrentLink())
- this->CurrentLink() = & this->Head();
-
- item->Unlink();
- }
- // end if block
-
- return this;
-
- } // end Detach
-
-
-
-
- /*=============================== ABLinkedList::NthLink ================================*/
- ABLink *ABLinkedList::NthLink(ABIndex n)
- {
- ABIndex index;
- ABLink *link;
-
- // begin here...
-
- if ((this->Count() < 1) || (n > this->Count()))
- return NULL;
-
- link = &this->Head();
- for (index = 1; (index <= n) && link; ++index)
- {
- link = link->NextLink();
- } // end for loop
-
- if (link == &this->Tail())
- return NULL;
- else
- return link;
- } // end NthLink
-
-
-
- /*=============================== ABLinkedList::GotoLink ================================*/
- ABLink *ABLinkedList::GotoLink(ABIndex n)
- {
- ABLink *link;
-
- // begin here...
-
- link = this->NthLink(n);
- if (link)
- this->CurrentLink() = link;
-
- return link;
- } // end GotoLink
-
-
-
- /*=============================== ABLinkedList::PreviousLink ================================*/
- ABLink *ABLinkedList::PreviousLink(void)
- {
- if (this->DoesntHaveCurrentLink())
- return NULL;
-
- if (this->CurrentLink()->PreviousLink() != &this->Head())
- this->CurrentLink() = this->CurrentLink()->PreviousLink();
-
- return this->CurrentLink();
- } // end PreviousLink
-
-
-
- /*=============================== ABLinkedList::NextLink ================================*/
- ABLink *ABLinkedList::NextLink(void)
- {
- if (this->DoesntHaveCurrentLink())
- return NULL;
-
- if (this->CurrentLink()->NextLink() != &this->Tail())
- this->CurrentLink() = this->CurrentLink()->NextLink();
-
- return this->CurrentLink();
- } // end NextLink
-
-
-
- /*=============================== ABLinkedList::FirstLink ================================*/
- ABLink *ABLinkedList::FirstLink(void)
- {
- if (this->IsntEmpty())
- return this->Head().NextLink();
- else
- return NULL;
- } // end FirstLink
-
-
-
- /*=============================== ABLinkedList::LastLink ================================*/
- ABLink *ABLinkedList::LastLink(void)
- {
- if (this->IsntEmpty())
- return this->Tail().PreviousLink();
- else
- return NULL;
- } // end LastLink
-
-
-
- /*=============================== ABLinkedList::Concatenate ================================*/
- //
- // ForEach is an internal method used to do something to all items in
- // the list.
- OSErr ABLinkedList::ForEach (ABMessage /* message */, void* /* data*/)
- {
- // OVERRIDE THIS METHOD...
- return noErr;
- } /// end ForEach
-
-
-
-
- // end of file.